package com.carrie.mdg.myviewtext.activity;

import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;

import com.carrie.mdg.myviewtext.R;
import com.carrie.mdg.myviewtext.adapter.FruitAdapter;
import com.carrie.mdg.myviewtext.entity.Fruit;

import java.util.ArrayList;
import java.util.List;

import androidLib.activity.BaseActivity;

public class RecyclerviewTextActivity extends BaseActivity {
    private List<Fruit> fruits = new ArrayList<>(30);
    private RecyclerView recyclerView;
    private FruitAdapter adapter;
    private TextService mTextService;

    public static void actionStart(Context context) {
        Intent intent = new Intent(context, RecyclerviewTextActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void initVariables() {
        initFruit();
    }

    @Override
    protected void initViews(Bundle savedInstanceState) {
        setContentView(R.layout.activity_recyclerview_text);
        recyclerView = (RecyclerView) findViewById(R.id.recyclerview);

//        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
//        linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
//        recyclerView.setLayoutManager(linearLayoutManager);

        GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 4);
        recyclerView.setLayoutManager(gridLayoutManager);

//        StaggeredGridLayoutManager staggeredGridLayoutManager = new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL);
//        recyclerView.setLayoutManager(staggeredGridLayoutManager);

        adapter = new FruitAdapter(fruits);
        recyclerView.setAdapter(adapter);

        mTextService = new TextService();
    }

    @Override
    protected void initEvent() {

    }

    @Override
    protected void loadData() {

    }

    private void initFruit() {
        Fruit fruit;
        for (int i = 0; i < 30; i++) {
            fruit = new Fruit();
            if (i % 4 == 0) {
                fruit.setFruitName("bananabanana");
                fruits.add(fruit);
            } else if (i % 2 == 0) {
                fruit.setFruitName("applebananabananabananabananabananabananabananabananabananabanana");
                fruits.add(fruit);
            } else {
                fruit.setFruitName("strawberrybananabanana");
                fruits.add(fruit);
            }
        }
    }
}
